/*****************************************************************************

FileName: 	<BitmapDecode.cpp>

File Description:
Converts uncompressed BMP file into YUV420 file

*****************************************************************************/


#include "dbmpafx.h"


/*****************************************************************************

Routine: InitBitmapDecode

returns        	: void
Description			: Initializes Bitmap Decoder
*****************************************************************************/
ErrorType InitBitmapDecode(CodecHandle hCodec, 
						   void *pInMetaData, 
						   void *pOutMetaData)
{

	bmpCodecObject *pvc;

	/* Initialize Codec Private Data */
	hCodec->pPrivateData = malloc(sizeof(BitmapdCodecData));
	memset(hCodec->pPrivateData, 0x0, sizeof(BitmapdCodecData));

	/* Initialize Memory For Codec Private Data Structures */
	((BitmapdCodecData *)(hCodec->pPrivateData))->pBmpCodecObject = (bmpCodecObject *)malloc(sizeof(bmpCodecObject));
	memset(((BitmapdCodecData *)(hCodec->pPrivateData))->pBmpCodecObject, 0x0, sizeof(bmpCodecObject));
	pvc = ((BitmapdCodecData *)(hCodec->pPrivateData))->pBmpCodecObject;


	/* Read File Headers */
	fseek(((BitmapdInMetaData*)pInMetaData)->pFile, 0, SEEK_SET);
	ReadBitmapFileHeader(pvc, ((BitmapdInMetaData*)pInMetaData)->pFile);
	ReadBitmapInfoHeader(pvc, ((BitmapdInMetaData*)pInMetaData)->pFile);
	((BitmapdOutMetaData*)pOutMetaData)->nWidth  = (pvc->bmih).biWidth;
	((BitmapdOutMetaData*)pOutMetaData)->nHeight = (pvc->bmih).biHeight;

	return ErrorNone;
}



/*****************************************************************************

Routine: BitmapDecode

returns        	: void
Description			: Bitmap Decoder
*****************************************************************************/
ErrorType BitmapDecode(CodecHandle hCodec, 
					   void *pInMetaData, 
					   void *pOutMetaData)
{

	bmpCodecObject *pvc;
	pvc = ((BitmapdCodecData *)(hCodec->pPrivateData))->pBmpCodecObject;

	/* Read File Headers */
	fseek(((BitmapdInMetaData*)pInMetaData)->pFile, 0, SEEK_SET);
	ReadBMPFrame(pvc, ((BitmapdOutMetaData*)pOutMetaData)->pBuffer, ((BitmapdInMetaData*)pInMetaData)->pFile);

	return ErrorNone;
}


